package net.luohuasheng.bee.proxy.mybatis.executor.intercetor;


import net.luohuasheng.bee.proxy.jdbc.LoggingProxy;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author panda
 */
public interface BaseInterceptor extends Interceptor {
    XMLLanguageDriver LANGUAGE_DRIVER = new XMLLanguageDriver();

    /**
     * mybatis 日志打印
     *
     * @param ms MappedStatement对象
     */
    default void callLog(MappedStatement ms) {
        LoggingProxy.addLogCall((text, input) -> {
            Logger logger = LoggerFactory.getLogger(ms.getId());
            LoggingProxy.localPrint(logger, text, input);
        });
    }

    enum Index {

        FOUR_INDEX(4),

        SIX_INDEX(6),

        /**
         * mybatis 上下文索引
         */
        MAPPED_STATEMENT_INDEX(0),
        /**
         * 参数属性索引
         */
        PARAMETER_INDEX(1),
        /**
         * 分页属性索引
         */
        ROWBOUNDS_INDEX(2),
        /**
         * 结果处理器索引
         */
        RESULT_HANDLER_INDEX(3),
        /**
         * 缓存器索引
         */
        CACHE_KEY_INDEX(4),

        /**
         * SQL处理器索引
         */
        BOUND_SQL_INDEX(5);


        private final int anInt;

        Index(int anInt) {
            this.anInt = anInt;
        }

        public int getAnInt() {
            return anInt;
        }


    }
}
